/**
 *  数组操作方法工具类
 */

/*将数组去重*/
function unique(arr, attribute) {
    let new_arr = [];
    let json_arr = [];
    for (let i = 0; i < arr.length; i++) {
        if (new_arr.indexOf(arr[i][attribute]) == -1) {
            new_arr.push(arr[i][attribute]);
            json_arr.push(arr[i]);
        }
    }
    return json_arr;
}

//  数组排序
function reorder(arr, oldIndex, newIndex) {
    if (oldIndex == newIndex) return arr;
    if (oldIndex > newIndex) {
        arr.splice(newIndex, 0, arr[oldIndex])
        arr.splice(oldIndex + 1, 1);
    } else {
        arr.splice(newIndex, 0, arr[oldIndex]);
        arr.splice(oldIndex - 1, 1);
    }
    return arr;
}

//装载网格
function loadOptions(grid01, columnsName, columns, suffix) {
    //后端获取记忆列
    $.ajax({
        url: 'userDeploy/query/batch',
        contentType: 'application/json',
        type: 'POST',
        dataType: "json",
        data: JSON.stringify(columnsName),
        success: function (data) {
            if (!data) {
                $.messager.alert('提示', '无法加载网格配置,请重新打开页面!', 'warning')
                return;
            }
            for (let x of columns) {
                let col = x['field'];
                if (suffix) col += suffix;
                if (data[col] == undefined) continue;
                let width = data[col]['width'];
                let hidden = data[col]['hidden'];
                x['width'] = width ? parseFloat(width) : 0;
                x['hidden'] = hidden;
                x['serialNo'] = data[col]['serialNo'];
            }
            columns.sort((x, y) => x.serialNo - y.serialNo);
            grid01.setOptions({
                columns: columns
            });
        },
        error: function () {
            grid01.setOptions({
                columns: columns
            });
        }
    });
}

// 静态变量
const STATUS_ARR = [{id: 0, text: '停用'}, {id: 1, text: '正常'}];
